<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div class="align-center flex-wrap">
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-select v-model="state" placeholder="選擇審核狀態" size="large" style="width: 240px" class=" mr10 mb10">
          <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-select v-model="type" placeholder="選擇提現類型" size="large" style="width: 240px" class=" mr10 mb10">
          <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <div class="align-center mb10">
          <el-date-picker v-model="start" type="datetime" placeholder="开始时间" value-format="YYYY-MM-DD HH:mm:ss" />
          <span class="plr10 clr9fa">--</span>
          <el-date-picker v-model="end" type="datetime" placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss" />
        </div>

      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="getWithdrawList()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="bgblueg ptb20 radius10 w100p mt15 pl10 bold clr3c4">
      總金額：{{ withdrawTotal }}元
      <span class="ml15">審核中：{{ state0 }}元</span>
      <span class="ml15">已通過：{{ state1 }}元</span>

    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="uid" label="用戶訊息" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.user.id)">{{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="type_text" label="提現類型" min-width="100" />
          <el-table-column prop="money" label="提現金額" min-width="100" />
          <el-table-column prop="account_type_text" label="提現賬戶類型" min-width="150" />
          <el-table-column prop="is_refund_text" label="審核狀態" min-width="100">
            <template #default="scope">
              <div class="red" v-if="scope.row.state == 2">拒絕</div>
              <div class="blue" v-if="scope.row.state == 1">通過</div>
              <div class="yellow" v-if="scope.row.state == 0">審核中</div>
            </template>
          </el-table-column>
          <el-table-column prop="adminuser.username" label="審核人" min-width="100" />
          <el-table-column prop="created_at" label="創建時間" min-width="200" />
          <el-table-column prop="updated_at" label="更新時間" min-width="200" />
          <el-table-column prop="is_refund" label="打款狀態" min-width="100">
            <template #default="scope">
              <div class="blue" v-if="scope.row.is_refund == 1">已打款</div>
              <div class="red" v-else>未打款</div>

            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作" width="80" fixed="right">
            <template #default="scope">
              <div class=" pointer" @click="edit(scope.row)">編輯</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { withdrawList } from '@/api/finance.js'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getWithdrawList()
})
const withdrawTotal = ref(0)
const state0 = ref(0)
const state1 = ref(0)

// 提现管理列表
const getWithdrawList = () => {
  withdrawList({
    page: currentPage.value,
    uid: uid.value,
    state: state.value,
    type: type.value,
    start: start.value,
    end: end.value
  }).then((res) => {
    console.log('提现管理列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
    withdrawTotal.value = res.total
    state0.value = res.state0
    state1.value = res.state1
  })
}
const uid = ref('')
const state = ref('')
const type = ref('')
const start = ref('')
const end = ref('')
const reset = () => {
  uid.value = ''
  state.value = ''
  type.value = ''
  start.value = ''
  end.value = ''
  getWithdrawList()
}
const dialogTableVisible = ref(false)
const stateOptions = [
  {
    label: '審核中',
    value: '0'
  },
  {
    label: '通過',
    value: '1'
  },
  {
    label: '拒絕',
    value: '2'
  },
]
const typeOptions = [
  {
    label: '訂單餘額',
    value: 'order_wallet'
  },
  {
    label: '車費餘額',
    value: 'fare_wallet'
  },
  {
    label: '打賞餘額',
    value: 'reward_wallet'
  },
  {
    label: '邀請獎勵',
    value: 'agent_wallet'
  },
]
const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getWithdrawList()
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'addNotice' })
}
const edit = (row) => {
  router.push({ path: 'editPage', query: { row: JSON.stringify(row), type: 'withdraw' } })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
 